package BinaryTreePackage;

/**
 * @author Lzm
 * @version 1.0
 */
public class minDepth_ {


  // 后序遍历
  public int minDepth(TreeNode root) {
    if (root == null){
      return 0;
    }
    int leftDepth = minDepth(root.left);
    int rightDepth = minDepth(root.right);
    // 排除左右子树为空的情况0
    if (root.left != null && root.right == null){
      return 1 + leftDepth;
    }
    if (root.left == null && root.right != null){
      return 1 + rightDepth;
    }
    return 1 + Math.min(leftDepth,rightDepth);
  }
}
